package design_patterns;
/**
 * 工厂方法模式
 * @author Fairy
 */

public class FactoryPattern {
    public static void main(String[] args) throws Exception {
        Factory operFactory = new AddFactory();
        Operation oper = operFactory.createOperation();
        //Operation oper = new AddFactory().createOperation();
        oper.setNumberA(1);
        oper.setNumberB(2);
        double result = oper.getResult();
        System.out.println(result);
    }
}
interface Factory {
    Operation createOperation();
}
class AddFactory implements Factory {

    @Override
    public Operation createOperation() {
        return new OperationAdd();
    }
}
class SubFactory implements Factory {

    @Override
    public Operation createOperation() {
        return new OperationSub();
    }
}
class MulFactory implements Factory {

    @Override
    public Operation createOperation() {
        return new OperationMul();
    }
}
class DivFactory implements Factory {

    @Override
    public Operation createOperation() {
        return new OperationDiv();
    }
}